# -*- coding: utf-8 -*-
# @Time    : 2020/12/19 23:57
# @Author  : Guo_Zhanyu
# @File    : testFlask.py
import requests, json

url = 'http://127.0.0.1:5000/'


class Chessman:
    """
    Define a Chessman's Properties.
    """
    def __init__(self, name, value, color):
        """
        Init a Chessman.

        :param name: Chessman's name -> str()
        :param value: Chessman's value -> int()
        :param color: Chessman's color -> QColor()
        """
        self.name = name
        self.value = value
        self.color = color
        pass
    pass


def getRestPlay():
    r = requests.get(url + 'rest/play')
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestPlayState(s):
    data = {'newvalue': s}
    r = requests.get(url + 'rest/play/state', params=data)
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestPlayReport():
    r = requests.get(url + 'rest/play/report')
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestPlayer():
    r = requests.get(url + 'rest/player')
    rev = r.json()
    print(rev, type(rev))
    pass


def postRestPlayer(chessman):
    ip = '127.0.0.1'
    color = chessman.name
    post = {'ip': ip, 'color': color}
    r = requests.post(url + 'rest/player', data=post)
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestPlayerID(id_):
    r = requests.get(url + 'rest/player/%d' % id_)
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestBoard():
    r = requests.get(url + 'rest/board')
    rev = r.json()
    print(rev, type(rev))
    pass


def postRestBoard(x, y, id_, color):
    send = dict()
    send['id'] = id_
    send['x'] = x
    send['y'] = y
    send['color'] = color
    r = requests.post(url + 'rest/board', data=send)
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestActionLast():
    r = requests.get(url + 'rest/action/last')
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestActionCount():
    r = requests.get(url + 'rest/action/count')
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestActionValue(value):
    r = requests.get(url + 'rest/action/%d' % value)
    rev = r.json()
    print(rev, type(rev))
    pass


def getRestActionStep(start, end):
    data = {
        'stepfrom': start,
        'stepto': end
    }
    r = requests.get(url + 'rest/action', params=data)
    rev = r.json()
    print(rev, type(rev))
    pass

# getRestPlay()
# getRestPlayState(2)
# getRestPlayReport()
getRestPlayer()
a = Chessman('black', 1, None)
b = Chessman('white', 2, None)
postRestPlayer(a)
postRestPlayer(b)
# getRestPlayerID(1)
# getRestBoard()
# postRestBoard(1, 2, 1, 'black')
# postRestBoard(1, 3, 2, 'white')
# getRestActionLast()
# getRestActionCount()
# getRestActionValue(1)
# getRestActionStep(1, 2)
